import Vue from 'vue';
import App from './app.vue';
import underscore from 'vue-underscore';
import router from '@/router/router.js';
import VantGreen from 'vant-green';
import { Toast } from 'vant-green';
import 'vant-green/lib/index.css';
import BaiduMap from 'vue-baidu-map'
Vue.use(BaiduMap, {
    ak: 'KFedKaUaPYdb3eiEGvSK3dezfnlNqFxD'
})

// import VueAMap from 'vue-amap' // 引入插件
// Vue.use(VueAMap) // 使用插件
// VueAMap.initAMapApiLoader({ // 初始化插件
//     key: '9cce245ade69b44fa2ab757b570fc53f', // 高德key
//     plugin: ['AMap.Geocoder', 'AMap.PlaceSearch', 'AMap.Geolocation', 'AMap.CitySearch'], // 插件集合，根据自己的需求添加
//     uiVersion: '1.0.11', // 不加会报错，加上吧
//     v: '1.4.15' // 默认高德 sdk 版本为 1.4.4
// })

import commonUtil from "@/utils/common.js";
Vue.prototype.$commonUtil = commonUtil;
Vue.prototype.$createIndex = commonUtil.createIndex;

Vue.config.devtools = true;

import '@babel/polyfill';
import 'proto-polyfill';


//引入全局服务访问路径
import server from '@/const/global.js';
Vue.prototype.server = server;

// import 'swiper/dist/css/swiper.min.css';
// import 'swiper/dist/js/swiper.min';

import '@/assets/styles/common.scss' // global css

//验证
import VeeValidate from 'vee-validate';
import zh_CN from 'vee-validate/dist/locale/zh_CN';
const config = {
	fieldsBagName: 'vee-fields', // 默认为 fields
	events: 'change|input|blur|custom',
	locale: 'zh_CN',
	dictionary: {
		zh_CN
	}
};
Vue.use(VeeValidate, config);
Vue.use(VantGreen);
Vue.use(Toast);


// Vue.prototype.getcookie = function (a) {
//     // console.log(a)
//     var d;
//     var b = document.cookie;
//     // console.log(b)
//     var c = b.split(";");
//     for (let e = 0; e < c.length; e++) {
//         var f = c[e].split("=");
//         if (a == f[0].toString().trim()) {
//             d = f[1];
//             break;
//         }
//     } if (void 0 == d || null == d) {
//         return "";
//     }
//     else {
//         var g = unescape(d.trim());
//         return g;
//     }
// }


// 自定义 axios
import * as axs from '@/api/common.js';
Vue.prototype.$ax = axs;

Vue.prototype.$toast =Toast


import * as  echarts from 'echarts';
Vue.prototype.$echarts = echarts;


import store from '@/store/main.js';
Vue.prototype.$store = store;

Vue.use(router);
Vue.use(underscore);

const root = document.createElement('div');
document.body.appendChild(root);


Vue.directive('bpoint', {
	bind: (el, binding, vnode) => {
	  el.addEventListener('click', () => {
		//自定义数据
		const data = binding.value;
		//调用setPoint.js
		bPoint.setPoint(data)
	  }, false);
	}
  })

new Vue({
	router,
	data: {
		eventHub: new Vue()
	},
	beforeCreate() {
		var lastTime = 0;
		var vendors = ['ms', 'moz', 'webkit', 'o'];
		for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
			window.requestAnimationFrame =
        window[vendors[x] + 'RequestAnimationFrame'];
			window.cancelAnimationFrame =
        window[vendors[x] + 'CancelAnimationFrame'] ||
        window[vendors[x] + 'CancelRequestAnimationFrame'];
		}

		if (!window.requestAnimationFrame) {
		// window.requestAnimationFrame = function(callback, element) {
			window.requestAnimationFrame = function(callback) {
				var currTime = new Date().getTime();
				var timeToCall = Math.max(0, 16 - (currTime - lastTime));
				var id = window.setTimeout(function() {
					callback(currTime + timeToCall);
				}, timeToCall);
				lastTime = currTime + timeToCall;
				return id;
			};
		}

		if (!window.cancelAnimationFrame) {
			window.cancelAnimationFrame = function(id) {
				clearTimeout(id);
			};
		}

		if (
			Function.prototype.bind &&
      window.console &&
      typeof console.log == 'object'
		) {
			[
				'log',
				'info',
				'warn',
				'error',
				'assert',
				'dir',
				'clear',
				'profile',
				'profileEnd'
			].forEach(function(method) {
				console[method] = this.bind(console[method], console);
			}, Function.prototype.call);
		}
	},
	render: h => h(App),
}).$mount(root);



